﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;
using BestLifePOS_Core.DomainObjects;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeInsertPackageDataAction:BestLifeDataAction<int>
    {
        private Package GvPackage;
       
        public BestLifeInsertPackageDataAction(Package PPackage)
        {
            GvPackage = PPackage;
         
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertPackage";

                LvCommand.Parameters.Add(new SqlParameter("@Package_ID", GvPackage.Package_ID.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@PL_Id", GvPackage.PL_ID.ToString()));


                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvPackage.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvPackage.User_Modify.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvPackage.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvPackage.Last_Modify.ToString())));

                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 
            
            }
            catch(BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }

        }
    }
}
